﻿<!-- saved from url=(0014)about:internet -->
<html>
<head>
    <title></title>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript" src="math3d.js"></script>
    <script type="text/javascript" src="plane.js"></script>
    <script type="text/javascript">
        google.load("earth", "1");
        google.load('maps', '2.x', { 'other_params': 'sensor=false' });
        var ge;
        var geocoder;
        function init() {

            google.earth.createInstance('earth', initCallback, failureCB);
            geocoder = new GClientGeocoder();
            
        }

     
        function initCallback(instance) {
            ge = instance;
            ge.getWindow().setVisibility(true);
            ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
            ge.getOptions().setFlyToSpeed(ge.SPEED_TELEPORT);
            doGeocode('50 avenue des Champs-élysées, 75008 Paris, France');
            truck = new Truck();
        }
        function failureCB(errorCode) {
            alert(errorCode);
        }
        function doGeocode(address) {
            geocoder.getLatLng(address, function (point) {
                if (point) {
                    var lookAt = ge.createLookAt('');
                    truck.teleportTo(point.y, point.x);
                    //lookAt.set(point.y, point.x, 10, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 30, 200);
                    //ge.getView().setAbstractView(lookAt);
                }
            });
        }
        google.setOnLoadCallback(init);
        function setLongitude(lookAt, speed) {
            lookAt.setLongitude(lookAt.getLongitude() + speed);
            ge.getView().setAbstractView(lookAt);
        }

        function setLatitude(lookAt, speed) {
            lookAt.setLatitude(lookAt.getLatitude() + speed);
            ge.getView().setAbstractView(lookAt);
        }
        function tiltLookAt(lookAt, angle) {
            lookAt.setTilt(lookAt.getTilt() + angle);
            ge.getView().setAbstractView(lookAt);
        }
        function tiltCamera(camera, angle) {
            camera.setTilt(camera.getTilt() + angle);
            ge.getView().setAbstractView(camera);
        }
        function rollCamera(camera, angle) {
            camera.setRoll(camera.getRoll() + angle);
            ge.getView().setAbstractView(camera);
        }
        function zoom(camera, altitude) {
            camera.setAltitude(altitude);
            ge.getView().setAbstractView(camera);
        }

        $(document).keypress(function (e) {
            var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
            var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
            if (e.which == 106) setLongitude(lookAt, -0.0001); //j
            if (e.which == 108) setLongitude(lookAt, 0.0001); //l
            if (e.which == 105) setLatitude(lookAt, 0.0001); //i
            if (e.which == 107) setLatitude(lookAt, -0.0001); //k
            if (e.which == 112) tiltLookAt(lookAt, -3); //p
            if (e.which == 109) tiltLookAt(lookAt, 3); //m
            if (e.which == 117) rollCamera(camera, -3); //u
            if (e.which == 111) rollCamera(camera, 3); //o
            if (e.which == 121) tiltCamera(camera, -3); //y
            if (e.which == 104) tiltCamera(camera, 3); //h
            if (e.which == 45) zoom(camera, camera.getAltitude() / 1.2); //-
            if (e.which == 43) zoom(camera, camera.getAltitude() * 1.2); //+
        });
    </script>
    <script type="text/javascript">
        function OnjKinectReady() {
            jKinect.initKinect(true, false);
        }

        function OnKinectReady() {
            jKinect.bind("SkeletonFrameReady", function (json) {
                var joints = jKinect.parseJSON(json);
                if (ge != undefined && ge.getView() != undefined) {
                    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
                    if (joints["Head"].Z - joints["HipCenter"].Z < -0.15 || joints["Head"].Z - joints["HipCenter"].Z > 0.1)
                        zoom(camera, camera.getAltitude() * (Math.abs(1.0 + (joints["Head"].Z - joints["HipCenter"].Z) / 2.0)));
                }
            });
            jKinect.bind("HandsPosition", function (json) {
                var positions = jKinect.parseJSON(json);
                if (jKinect.distance(positions["HandLeft"], positions["HandRight"]) > 1) {
                    if (positions["HandLeft"].Y - 20 < positions["HandRight"].Y) {
                        leftButtonDown = true;
                        rightButtonDown = false;
                    }
                    if (positions["HandLeft"].Y + 20 > positions["HandRight"].Y) {
                        leftButtonDown = false;
                        rightButtonDown = true;
                    }
                    else {
                        leftButtonDown = true;
                        rightButtonDown = false;
                    }
                    steerAngle = Math.atan2(positions["HandLeft"].Y - positions["HandRight"].Y, positions["HandLeft"].X - positions["HandRight"].X);
                }
            });
        
            setInterval("jKinect.getNextSkeletonFrame()", 50);
        }
    </script>
</head>
<body  onunload="GUnload()" onkeydown="return keyDown(event);" onkeyup="return keyUp(event);">
    <div id="earth" style="height: 100%; width: 100%;">
    </div>
</body>
</html>
